/*	kd:
	
	Shopkeepers are the dumbest feature in this mod.
	
	*/

// kd: First of all, you want a list of all of them. In older Guncaster versions
// there used to be a menu entry in convenience options to set the shopkeeper,
// but that cannot be updated with addons.

// So now, you can find all shopkeepers here (since this is generated after
// all mods are loaded). A button in the shop will cycle through them.

class Gc_ShopkeeperList {
	protected Array <class <Gcs_Shopkeeper> >	shopkeeper_type;
	protected int								shopkeeper_count;
	
	int Count () const {
		return shopkeeper_count;
	}
	
	class <Gcs_Shopkeeper> At (int i) const {
		return shopkeeper_type [i];
	}
	
	void OnBuild () {
		shopkeeper_count = 0;
		shopkeeper_type.clear();
		
		let size = allactorclasses.size();
		
		for(let i = 0; i < size; i++) {
			let type = (class <Gcs_Shopkeeper>)(allactorclasses [i]);
			
			if(
			type &&
			!(type is "Gcs_TestKeeper") &&
			!(type.GetClassName() == "Gcs_Shopkeeper") &&
			shopkeeper_count == shopkeeper_type.find(type)) {
				shopkeeper_type.push(type);
				shopkeeper_count++;
			}
		}
	}
}

class Gc_ShopkeeperLoad : StaticEventHandler {
	protected Gc_ShopkeeperList		keepers;
	
	override void OnRegister () {
		keepers = new("Gc_ShopkeeperList");
		
		if(keepers) {
			keepers.OnBuild();
			
			let count = keepers.Count();
			
			console.printf(
				"\c[gold]For you, I%s.",
				count == 0 ?
				" won't even bother drinking" :
				"'ll raise my cup " .. (
					count == 1 ? "once" : "" .. count .. " times"));
		}
	}
	
	static Gc_ShopkeeperList Ptr () {
		let handler = Gc_ShopkeeperLoad(Find("Gc_ShopkeeperLoad"));
		
		if(handler) {
			return handler.keepers;
		}
		
		return NULL;
	}
}
